<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Models\CommoditySeries;
use App\Models\Commodity;

class CommoditySeriesController extends Controller
{
    use ModelForm;
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header('商品系列');
            $content->description('管理');
            $content->body($this->grid());
        });
    }

    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {
            $content->header('商品系列');
            $content->description('编辑');

            $content->body($this->form()->edit($id));
        });
    }

    public function create()
    {
        return Admin::content(function (Content $content) {
            $content->header('商品系列');
            $content->description('创建');

            $content->body($this->form());
        });
    }

    protected function grid()
    {
        return Admin::grid(CommoditySeries::class, function (Grid $grid) {
            // $grid->position_tags('轮播图序号');
            $grid->id('序号');
            $grid->commodity_id('商品id号');
            $grid->title('系列名称');
            $grid->disableFilter();
            $grid->disableExport();
            // $grid->disableCreateButton();
            // $grid->disablePagination();
            $grid->disableFilter();
            $grid->paginate(10);
            $grid->perPages([10,20,30]);
            $grid->disableRowSelector();
            // $grid->disableCreateButton();
            // $grid->disableActions();
            $grid->actions(function ($actions) {
                // $actions->disableDelete();
                // $actions->disableDelete();
            });
        });
    }

    protected function form()
    {
        return Admin::form(CommoditySeries::class, function (Form $form) {
            $form->select('commodity_id', '选中商品')->options(commodity::pluck('name', 'id'))->rules('required',[
           'required' => '分类名称不能为空!',
           // 'min' => '字符必须大于2个!'
]);;
            $form->text('title', '系列名称')->rules('required|min:2',[
           'required' => '系列名称不能为空!',
           'min' => '字符必须大于2个!'
]);;
        });
    }
  }
